# 09/10/2022 ;
library(tidyverse)
library(brms)
library(rstan)

options(mc.cores = parallel::detectCores())

#-------------------------------------------------------------------------------
# ESS COMPARATIVE SURVEY DATA ;
#-------------------------------------------------------------------------------
rm(list=ls())
load("DATA_ESS.RData")

#-------------------------------------------------------------------------------
# RC;
#-------------------------------------------------------------------------------
bprior <- c(prior(normal( 1,10), class = b, coef = "vignette1"),
            prior(normal(-1,10), class = b, coef = "vignette3"),
            prior(normal(-1,10), class = b, coef = "vignette4"))

rc_pay <- brm(sanction_pay ~ vignette + (1+vignette|cntry), data=ess, 
              family = cumulative(link = "logit", threshold = "flexible"),
              chains=4, iter=5000, prior=bprior, seed=1234)
summary(rc_pay)

rc_edu <- brm(sanction_edu ~ vignette + (1+vignette|cntry), data=ess, 
              family = cumulative(link = "logit", threshold = "flexible"),
              chains=4, iter=5000, prior=bprior, seed=1234)
summary(rc_edu)

rc_unp <- brm(sanction_unp ~ vignette + (1+vignette|cntry), data=ess, 
              family = cumulative(link = "logit", threshold = "flexible"),
              chains=4, iter=5000, prior=bprior, seed=1234)
summary(rc_unp)
   
#-------------------------------------------------------------------------------
# SAVE FINDINGS ;
#-------------------------------------------------------------------------------
save.image("TREAT_ORDINAL.RData")
